# -*- coding:utf-8 -*-
from PySide.QtGui import *
from PySide.QtCore import *
import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

class StackQQInfo(QDialog):
    def __init__(self,parent=None):
        super(StackQQInfo,self).__init__(parent)
        self.setWindowTitle(self.tr("QQInfo"))

        # 主分割窗口
        # 新建一个QSplitter类对象， 作为主分割窗口，并设定此分割窗口为水平分割窗口
        # QSplitter的第一个参数通过Qt::Horizontal 和 Qt::Vertical来设定为水平分割或垂直分割。
        mainSpliter=QSplitter(Qt.Horizontal)
        mainSpliter.setOpaqueResize(True)

        listWidget=QListWidget(mainSpliter)
        listWidget.insertItem(0,self.tr("个人基本资料"))
        listWidget.insertItem(1,self.tr("联系方式"))
        listWidget.insertItem(2,self.tr("详细信息"))

        frame=QFrame(mainSpliter)
        stackPanel=QStackedWidget()

        baseInfoWidget=BaseInfoWidget()
        contactWidget=ContactWidget()
        moreInfoWidget = MoreInfoWidget()
        stackPanel.setFrameStyle(QFrame.Panel | QFrame.Raised)
        stackPanel.addWidget(baseInfoWidget)
        stackPanel.addWidget(contactWidget)
        stackPanel.addWidget(moreInfoWidget)

        editButton=QPushButton(self.tr("修改"))
        closeButton=QPushButton(self.tr("关闭"))

        buttonLayout=QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(editButton)
        buttonLayout.addWidget(closeButton)

        mainLayout=QVBoxLayout(frame)
        mainLayout.setContentsMargins(10,10,10,10)
        mainLayout.addWidget(stackPanel)
        mainLayout.addLayout(buttonLayout)

        self.connect(listWidget,SIGNAL("currentRowChanged(int)"),stackPanel,SLOT("setCurrentIndex(int)"))
        self.connect(closeButton,SIGNAL("clicked()"),self,SLOT("close()"))

        layout=QHBoxLayout(self)
        layout.addWidget(mainSpliter)
        self.setLayout(layout)


class BaseInfoWidget(QWidget):
    def __init__(self,parent=None):
        super(BaseInfoWidget,self).__init__(parent)
        userLabel = QLabel(self.tr("用户名："))
        self.userEdit = QLineEdit()
        nameLabel = QLabel(self.tr("姓名："))
        self.nameEdit = QLineEdit()
        sexLabel = QLabel(self.tr("性别："))
        self.sexComboBox = QComboBox()
        self.sexComboBox.addItem(self.tr("男"))
        self.sexComboBox.addItem(self.tr("女"))
        deptLabel = QLabel(self.tr("部门："))
        self.deptAreaEdit = QTextEdit()
        ageLabel = QLabel(self.tr("年龄："))
        self.ageEdit = QLineEdit()
        remarkLabel = QLabel(self.tr("备注"))
        remarkLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)

        leftLayout = QGridLayout()
        leftLayout.addWidget(userLabel, 0, 0)
        leftLayout.addWidget(self.userEdit, 0, 1)
        leftLayout.addWidget(nameLabel, 1, 0)
        leftLayout.addWidget(self.nameEdit, 1, 1)
        leftLayout.addWidget(sexLabel, 2, 0)
        leftLayout.addWidget(self.sexComboBox, 2, 1)
        leftLayout.addWidget(deptLabel, 3, 0)
        leftLayout.addWidget(self.deptAreaEdit, 3, 1)
        leftLayout.addWidget(ageLabel, 4, 0)
        leftLayout.addWidget(self.ageEdit, 4, 1)
        leftLayout.addWidget(remarkLabel, 5, 0, 1, 2)
        # leftLayout.setColumnStretch(0,1)

        txLabel = QLabel(self.tr("头像"))
        txIconLabel = QLabel()
        icon = QPixmap("img/tx1.jpg")
        txIconLabel.setPixmap(icon)
        txIconLabel.resize(icon.width(), icon.height())
        iconPushButton = QPushButton(self.tr("改变"))
        hLayout = QHBoxLayout()
        hLayout.setSpacing(20)
        hLayout.addWidget(txLabel)
        hLayout.addWidget(txIconLabel)
        hLayout.addWidget(iconPushButton)

        grsmLabel = QLabel(self.tr("个人说明："))
        descTextEdit = QTextEdit()

        rightLayout = QVBoxLayout()
        rightLayout.setContentsMargins(10, 10, 10, 10)
        rightLayout.addLayout(hLayout)
        rightLayout.addWidget(grsmLabel)
        rightLayout.addWidget(descTextEdit)


        mainLayout = QGridLayout(self)
        mainLayout.setContentsMargins(10, 10, 10, 10)
        mainLayout.setSpacing(10)
        mainLayout.addLayout(leftLayout, 0, 0)
        mainLayout.addLayout(rightLayout, 0, 1)
        mainLayout.setSizeConstraint(QGridLayout.SetFixedSize)

class ContactWidget(QWidget):
    def __init__(self,parent=None):
        super(ContactWidget,self).__init__(parent)
        emailLabel=QLabel(self.tr("电子邮件"))
        nameLabel=QLabel(self.tr("姓名："))
        sexLabel=QLabel(self.tr("性别："))
        deptLabel=QLabel(self.tr("部门："))
        ageLabel=QLabel(self.tr("年龄："))
        remarkLabel=QLabel(self.tr("备注："))

        emailEdit=QLineEdit()
        nameEdit=QLineEdit()
        sexEdit=QLineEdit()
        deptEdit=QLineEdit()
        ageEdit=QLineEdit()
        remarkEdit=QLineEdit()

        layout=QGridLayout(self)
        layout.addWidget(emailLabel,0,0)
        layout.addWidget(emailEdit,0,1)
        layout.addWidget(nameLabel,1,0)
        layout.addWidget(nameEdit,1,1)
        layout.addWidget(sexLabel,2,0)
        layout.addWidget(sexEdit,2,1)
        layout.addWidget(deptLabel,3,0)
        layout.addWidget(deptEdit,3,1)
        layout.addWidget(ageLabel,4,0)
        layout.addWidget(ageEdit,4,1)
        layout.addWidget(remarkLabel,5,0)
        layout.addWidget(remarkEdit,5,1)

class MoreInfoWidget(QWidget):
    def __init__(self,parent=None):
        super(MoreInfoWidget, self).__init__(parent)

        areaLabel=QLabel(self.tr("国家/地区："))
        provinceLabel=QLabel(self.tr("省份："))
        cityLabel=QLabel(self.tr("城市："))
        remarkLabel=QLabel(self.tr("个人说明："))

        areaEdit=QLineEdit()
        provinceEdit=QLineEdit()
        cityEdit=QLineEdit()
        remarEdit=QTextEdit()

        grid=QGridLayout(self)
        grid.addWidget(areaLabel,0,0)
        grid.addWidget(areaEdit,0,1)
        grid.addWidget(provinceLabel,1,0)
        grid.addWidget(provinceEdit,1,1)
        grid.addWidget(cityLabel,2,0)
        grid.addWidget(cityEdit,2,1)
        grid.addWidget(remarkLabel,3,0)
        grid.addWidget(remarEdit,3,1)


if __name__ == "__main__":
    app=QApplication(sys.argv)
    stackQQInfo=StackQQInfo()
    stackQQInfo.show()
    sys.exit(app.exec_())